import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.ie.service import Service
from selenium.webdriver.ie.webdriver import WebDriver
from webdriver_manager.chrome import ChromeDriverManager
#打开浏览器_驱动管理
ChromeIns=ChromeDriverManager().install()

##创建谷歌浏览器驱动对象
driver=webdriver.Chrome(service=Service(ChromeIns))
driver.get("https://www.baidu.com/")

#点击百度的首页的图片功能,跳转到百度图片的首页
print("before:"+driver.title)
print("before:"+driver.current_url)
driver.find_element(By.CSS_SELECTOR,"#s-top-left > a:nth-child(6)").click()
time.sleep(3)
#获取当前页面的句柄_第一个标签页
curhandle=driver.current_window_handle
#获取所有的句柄
allhandle=driver.window_handles
#遍历句柄
for handle in allhandle:
    if handle != curhandle:
        driver.switch_to.window(handle)
    #打印信息
   # time.sleep(3)
    print("after:"+driver.title)
    print("after:"+driver.current_url)
    driver.quit()

